﻿
$(document).ready(function () {
    //$("#drcngaynhan").datepicker({ dateFormat: 'dd/mm/yy' });
    // $("#txt_todate").datepicker({ dateFormat: 'dd/mm/yy' });
    //$("#plistdatefrom").datepicker({ dateFormat: 'dd/mm/yy' });
    //$("#plistdateto").datepicker({ dateFormat: 'dd/mm/yy' });

    //    $("#txt_frdate").datepicker({ dateFormat: 'dd/mm/yy' });
    //    $("#txt_todate").datepicker({ dateFormat: 'dd/mm/yy' });

});

function checkNumber(num) {
    if (num != "") {
        if (isNaN(num) == true) {
            alert("Yêu cầu nhập số!");
            return false;
        }
        return true;
    }
    return true;
}

function CheckValue() {

    var textBoxes = $("input[type='text']");
    for (var i = 0; i < textBoxes.length; i++) {
        value = textBoxes[i].value;
        if (value != '' && value != null) {
            if (!IsNumeric(value)) {
                alert("Yêu cầu nhập số!");
                textBoxes[i].focus();
                return false;
            }
        } else {
            textBoxes[i].value = 0;
        }
    }
    return true;
}


function IsNumeric(sText) {
    var ValidChars = "0123456789,";
    var IsNumber = true;
    var Char;
    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}



function ClientStatus() {
    alert("Chuyên mục này đang xây dựng!");
    return;
}


function ClientUpdateAdmIllegal(NumUnit, RecordId) {
   
    drcngaynhan = document.getElementById("drpDaydrcngaynhan").options[document.getElementById("drpDaydrcngaynhan").selectedIndex].value + '/' + document.getElementById("drpMonthdrcngaynhan").options[document.getElementById("drpMonthdrcngaynhan").selectedIndex].value + '/' + document.getElementById("drpYeardrcngaynhan").options[document.getElementById("drpYeardrcngaynhan").selectedIndex].value;
    if (drcngaynhan == "//") {
        alert("Yêu cầu nhập ngày tháng!!!");
        return;
    } else {
        if (!CheckValue()) {
            return;
        } else {
            var ArrayUnit = GetValueArr(NumUnit);
            RetValue = Portal.SODC.IDIS.EditAdminIllegal.ServerSideSaveAdmIllegal(RecordId, drcngaynhan, ArrayUnit).value;
            if (RetValue.indexOf("ERROR") != -1) {
                alert(RetValue.replace("ERROR: ", ""));
                return;
            } else {
                alert(RetValue);
            }
        } 
    }
}

function CheckValue() {
    var textBoxes = $("input[type='text']");
    for (var i = 0; i < textBoxes.length; i++) {
        value = textBoxes[i].value;
        if (value != '' && value != null) {
            if (!IsNumeric(value)) {
                alert("Yêu cầu nhập số!");
                textBoxes[i].focus();
                return false;
            }
        } else {
            textBoxes[i].value = 0;
        }
    }
    return true;
}

function GetValueArr(total) {
    var ArrayUnit = Array();
    var start = 2;
    for (var iIndex = 0; iIndex < total; iIndex++) {
        value = document.getElementById("txt_" + iIndex).value;
        ArrayUnit[start] = value;
        start++;
    }
    return ArrayUnit;
}

function ClientDoSaveAdminIllegal(total) {

    drcngaynhan = document.getElementById("drpDaydrcngaynhan").options[document.getElementById("drpDaydrcngaynhan").selectedIndex].value + '/' + document.getElementById("drpMonthdrcngaynhan").options[document.getElementById("drpMonthdrcngaynhan").selectedIndex].value + '/' + document.getElementById("drpYeardrcngaynhan").options[document.getElementById("drpYeardrcngaynhan").selectedIndex].value;
    if (drcngaynhan == "//") {
        alert("Yêu cầu nhập ngày tháng!!!");
        return;
    } else {
        if (!CheckValue()) {            
            return;
        } else {
            var ArrayUnit = GetValueArr(total);
            RetValue = Portal.SODC.IDIS.AddNewAdmIllegal.ServerSideAddNewMinistryInput(drcngaynhan, ArrayUnit).value;
            if (RetValue.indexOf("ERROR") != -1) {
                alert(RetValue.replace("ERROR: ", ""));
                return;
            } else {
                alert(RetValue);
                ResetAllFieldAdminIllegal(total);
            }
        }
    }
}

function isValidDate(sText) {
    var reDate = /(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/(?:19|20\d{2})/;
    return reDate.test(sText);
}


function ResetAllFieldAdminIllegal(NumUnit) {
    var textBoxes = $("input[type='text']");
    for (var i = 0; i < textBoxes.length; i++) {
        textBoxes[i].value = "";
    }
}

/*function checkdate(date) {
var validformat = /^\d{2}\/\d{2}\/\d{4}$/;
var returnval = false;
if (!validformat.test(date)) {
alert("Nhập sai định dạng ngày.");
}
else {
var monthfield = date.split("/")[1];
var dayfield = date.split("/")[0];
var yearfield = date.split("/")[2];
var dayobj = new Date(yearfield, monthfield - 1, dayfield);
if ((dayobj.getMonth() + 1 != monthfield) || (dayobj.getDate() != dayfield) || (dayobj.getFullYear() != yearfield)) {
alert("Nhập theo định dạng ngày/tháng/năm.");
}
else {
returnval = true;
}
}
return returnval;
}*/




function ClientDoSimpleSearchAdmIllegal() {
    var frDate = document.getElementById("drpDaytxt_frdate").options[document.getElementById("drpDaytxt_frdate").selectedIndex].value + '/' + document.getElementById("drpMonthtxt_frdate").options[document.getElementById("drpMonthtxt_frdate").selectedIndex].value + '/' + document.getElementById("drpYeartxt_frdate").options[document.getElementById("drpYeartxt_frdate").selectedIndex].value;
    var toDate = document.getElementById("drpDaytxt_todate").options[document.getElementById("drpDaytxt_todate").selectedIndex].value + '/' + document.getElementById("drpMonthtxt_todate").options[document.getElementById("drpMonthtxt_todate").selectedIndex].value + '/' + document.getElementById("drpYeartxt_todate").options[document.getElementById("drpYeartxt_todate").selectedIndex].value;
    if (frDate == "//") {
        frDate = null;
    }
    if (toDate == "//") {
        toDate = null;
    }
    result = document.getElementById("ContentSearchResult");
    document.getElementById("divProcessingSearchResult").innerHTML = "";
    ps = null;
    var RetValue = Portal.SODC.IDIS.AdmIllegalMgr.GetResult('app', frDate, toDate, 0, "JumpPageSearchResultAdmIllegal", ps).value;
    if (RetValue.indexOf("ERROR") != -1) {
        alert(RetValue.replace("ERROR: ", ""));
        return;
    } else {
        result.innerHTML = RetValue;
    }
    if (frDate == "//" || toDate == "//") {
        alert("Chưa xác định được thời gian tìm kiếm!");
        result.innerHTML = "";
    }
}

function JumpPageSearchResultAdmIllegal(MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    document.getElementById("divProcessingSearchResult").innerHTML = Portal.SODC.IDIS.AdmIllegalMgr.GetProcessingText().value;
    setTimeout("RealJumpPageSearchResult('','" + MaxItems + "', 20, 10, '" + CurrentPage + "','RealJumpPageSearchResult')", 10);
}
function RealJumpPageSearchResult(WebpartId, MaxItems, ItemsPerRow, NoOfVisiblePage, CurrentPage, JumpJavaScript) {
    var frDate = null;
    var toDate = null;
    PageIndex = CurrentPage;
    var frDate = document.getElementById("drpDaytxt_frdate").options[document.getElementById("drpDaytxt_frdate").selectedIndex].value + '/' + document.getElementById("drpMonthtxt_frdate").options[document.getElementById("drpMonthtxt_frdate").selectedIndex].value + '/' + document.getElementById("drpYeartxt_frdate").options[document.getElementById("drpYeartxt_frdate").selectedIndex].value;
    var toDate = document.getElementById("drpDaytxt_todate").options[document.getElementById("drpDaytxt_todate").selectedIndex].value + '/' + document.getElementById("drpMonthtxt_todate").options[document.getElementById("drpMonthtxt_todate").selectedIndex].value + '/' + document.getElementById("drpYeartxt_todate").options[document.getElementById("drpYeartxt_todate").selectedIndex].value;
    var ps = null;
    retValue = Portal.SODC.IDIS.AdmIllegalMgr.GetResult(WebpartId, frDate, toDate, CurrentPage, JumpJavaScript, ps).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    document.getElementById("divProcessingSearchResult").innerHTML = "";
    document.getElementById("ContentSearchResult").innerHTML = retValue;
}

// Delete InterCoop Info
function DeleteAdmIllegal(RecordId) {
    Msg = Portal.SODC.IDIS.AdmIllegalMgr.GetConfirmDeleteMsg().value;
    if (confirm(Msg) == false) return;
    retVal = Portal.SODC.IDIS.AdmIllegalMgr.ServerSideDeleteAdmiIllegal(RecordId).value;
    if (retVal.indexOf("ERROR") != -1) {
        alert(retVal);
        return;
    }
    alert(retVal);
    ClientDoSearchByLocation();
}

function ClientExportDataAdmIllegal() {

    var frDate = document.getElementById("drpDaytxt_frdate").options[document.getElementById("drpDaytxt_frdate").selectedIndex].value + '/' + document.getElementById("drpMonthtxt_frdate").options[document.getElementById("drpMonthtxt_frdate").selectedIndex].value + '/' + document.getElementById("drpYeartxt_frdate").options[document.getElementById("drpYeartxt_frdate").selectedIndex].value;
    var toDate = document.getElementById("drpDaytxt_todate").options[document.getElementById("drpDaytxt_todate").selectedIndex].value + '/' + document.getElementById("drpMonthtxt_todate").options[document.getElementById("drpMonthtxt_todate").selectedIndex].value + '/' + document.getElementById("drpYeartxt_todate").options[document.getElementById("drpYeartxt_todate").selectedIndex].value;
    if (frDate == "//") {
        frDate = null;
    }
    if (toDate == "//") {
        toDate = null;
    }

    var Ret = Portal.SODC.IDIS.AdmIllegalMgr.ServerExportDataAdm(frDate, toDate).value;

    document.getElementById("divProcessingSearchResult").innerHTML = "Hệ thống đang xử lý";
    if (Ret.indexOf("ERROR") != -1) {
        alert(Ret.replace("ERROR: ", ""));
        document.getElementById("divProcessingSearchResult").innerHTML = "";
        return;
    } else {
        document.getElementById("divProcessingSearchResult").innerHTML = "";
        window.open(Ret, "_blank");
    }
    if (frDate == "//" || toDate == "//") {
        alert("Chưa xác định được thời gian tìm kiếm!");
        result.innerHTML = "";
        return;
    }

}

function ShowValue(Id) {
    var value = document.getElementById(Id).value
    if (value != "") {
        document.getElementById("lb_" + Id).innerHTML = Portal.SODC.IDIS.Dictionarys.ReformatNumberVie(value).value;
    } else {
        alert("Bạn phải nhập giá trị để xem tra dữ liệu!");
        return;
    }
}
     